﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.XPath;

namespace ObviousCode.UI.Aspect.ConfigHandler
{
    public class ConfigurationHandler : IConfigurationSectionHandler
    {
        public ConfigurationHandler()
        {

        }

        #region IConfigurationSectionHandler Members

        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            XPathNavigator navigator = section.CreateNavigator();
            
            string objectType = (string)navigator.Evaluate("string(@type)");
            
            Type type = Type.GetType(objectType);
            
            XmlSerializer serializer = new XmlSerializer(type);
            
            XmlNodeReader reader = new XmlNodeReader(section);
            
            return serializer.Deserialize(reader);
        }

        #endregion
    }
}
